package com.yihr;

public class ApiResponse<T> {

    private static final String OK = "ok";
    private static final String ERROR = "error";

    private Meta mt;
    private T data;

    private String jwt;

    public ApiResponse success() {
        this.mt = new Meta(true, OK);
        return this;
    }

    public ApiResponse success(T data) {
        this.mt = new Meta(true, OK);
        this.data = data;
        return this;
    }

    public ApiResponse failure() {
        this.mt = new Meta(false, ERROR);
        return this;
    }

    public ApiResponse failure(String message) {
        this.mt = new Meta(false, message);
        return this;
    }

    public ApiResponse jwt(String jwt) {
        this.jwt = jwt;
        return this;
    }

    public Meta getMt() {
        return mt;
    }

    public Object getData() {
        return data;
    }

    public String getJwt() {
        return jwt;
    }

    public void setJwt(String jwt) {
        this.jwt = jwt;
    }

    @Override
    public String toString() {
        return "ApiResponse{" +
                "mt=" + mt +
                ", data=" + data +
                '}';
    }

    public class Meta {
        private boolean suc;
        private String msg;

        public Meta() {
        }

        public Meta(boolean suc) {
            this.suc = suc;
        }

        @Override
        public String toString() {
            return "Meta{" +
                    "suc=" + suc +
                    ", msg='" + msg + '\'' +
                    '}';
        }

        public Meta(boolean suc, String message) {
            this.suc = suc;
            this.msg = message;
        }

        public boolean isSuc() {
            return suc;
        }

        public String getMsg() {
            return msg;
        }
    }
}
